 begintownscript;	

 variables;
int i,j,k,r1,choice;
short weapon,hip;
string dlgstr;
body;
beginstate INIT_STATE;

	set_level(6,5);

	set_flag(99,9,(coins_amount() / 100));
	set_flag(99,10,(coins_amount() % 100));
	pay_coins(coins_amount());

	set_name(9,"Sergeant Benning");

	if (get_flag(2,5) == 0) {
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"You woke up a few hours ago, bruised and bleeding, in a squalid dungeon. The bandits had stripped you of your money, armor and weapons. The first thing you saw was two men being dragged screaming upstairs. They were the volunteers.",0);
		add_dialog_str(1,"A skinny bucktoothed bandit had been placed to guard you and the other prisoners. You soon found out that the others was only private Halter in the cell next to yours and he's in a bad shape.",0);
		add_dialog_str(2,"The bucktoothed jailer only snarled at your questions and grinned stupidly. As the hours passed, life found its way back in your limbs. Now you are all alone it seems in an old fort infested with bandits.",0);
		add_dialog_str(3,"You come up with a things-to-do list: 1) Escape. 2) Get your gear back. 3) If possible kill the leader of the bandits.",0);
		run_dialog(1);
		set_flag(2,5,1);
}

	set_character_pose(9,14);

	if (get_flag(1,0) == 0) {
		take_item_char_item(0,1,0,3);
		change_char_health(1000,-500);
		change_char_health(0,get_max_health(0) / 2);
		change_char_health(1,get_max_health(1) / 3);
		change_char_health(2,get_max_health(2) / 6);
		change_char_energy(1000,-200);
		set_flag(1,0,1);
}

	if (get_flag(2,6) == 3) {
		relocate_character(9,8,3);

		set_character_pose(9,0);
		set_character_facing(9,4);
}
	 break;	
beginstate START_STATE;

	if (get_flag(2,0) == 0)
		approach_waypoint(6,0,0);

	if ((dist_to_waypoint(6,0) == 0) && (get_flag(2,0) == 0)) {
		set_flag(2,0,1);
		reset_dialog();
		add_dialog_str(0,"The bucktoothed bandit rattles the bars of your cell with a rusty knife. _Soup's up, y'hear! Drenton wants you to be fed for now. I reckon you should thank him when y' sees him. Now come. Come get yer food._",0);
		add_dialog_str(1,"He holds a bowl of steming soup just outside the cell bars. You notice a keyring hanging from his belt. The fool stands so close to the bars you could try and grab him.",0);
		add_dialog_choice(0,"Grab the bowl.");
		add_dialog_choice(1,"Grab the bandit.");
		choice = run_dialog(1);

		if (choice == 1) {
			message_dialog("You make a grab for the bowl of soup, but the bandit pulls the bowl away from your grasp. He steps away from the cell door and drops the bowl on the ground. _Oops!_ He exclaims with a grin.","_Looks like yer not eating today. Unless you can lick some off the floor._ The bandit chortles and moves back to his table.");
			set_flag(2,0,2);
}
		if (choice == 2) {
			play_sound(29);
			message_dialog("You pretend to make a grab for the bowl, but once your hand leaves the cell you grab the bandit's neck tightly and ram his forehead into the bars. He folds down with a groan and manages to spill the soup on you.","You take keyring from the bandits belt.");
			set_flag(2,0,10);
			change_spec_item(1,1);
			set_character_pose(6,14);
			force_instant_terrain_redraw();
			set_mobility(6,0);
}
}
	if (get_flag(2,0) == 2) {
		return_to_start(6,0);
}

	if ((get_flag(2,0) == 2) && (char_on_spot(9,13) == 6))
		set_flag(2,0,3);

	if ((get_flag(2,0) == 3) && (get_flag(2,1) != 21))
		inc_flag(2,1,1);

	if (get_flag(2,1) == 10) {
		reset_dialog();
		add_dialog_str(0,"The bandit jailer pulls out a bottle underneath the table. He uncorks it and takes a swig from it. The smell coming from the bottle is very strong and you've come across it before. He's drinking gremlin wine.",0);
		add_dialog_str(1,"Gremlin wine is very potent and the bandit is not drinking it smartly. He takes another hefty swig and sets the bottle to the table. You notice that his hand is already moving shakily.",0);
		add_dialog_choice(0,"Wait.");
		add_dialog_choice(1,"Begin to groan with pain.");
		choice = run_dialog(1);

		if (choice == 2)
			set_state_continue(12);
}
	if (get_flag(2,1) == 20) {
		set_flag(2,1,21);
		set_flag(2,0,4);
		message_dialog("The bottle escapes the jailer's grasp and shatters to the floor. The bandit's head droops and you hear snoring. The gremlin wine was too much for him. As the bandit shifts in his sleep the keyring on his belt jingles.","The bandit is too far away for you to reach the keyring by hand. If only there was some way for you to reach the keyring you could escape.");
}

	if ((get_flag(2,0) == 4) && (has_num_of_item(79) == 3) && (has_special_item(2))) {
		message_dialog("Using the hay to tie the sticks together you manage to make a pole that might reach the keyring. You position yourself as close to the dozing bandit as the bars allow you to and reach for the keys.","Fortunately the sticks hold together and the ring parts from the bandit's belt. You carefully pull it to your cell.");
		change_spec_item(1,1);
		set_flag(2,0,5);
}
break;	

beginstate EXIT_STATE;
	if (get_flag(0,3) == 0)
		set_flag(0,3,1);

break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0,"The stair ascend to the main level of the fort and in the middle of dozens of angry bandits. Are you ready to leave the dungeon?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"Not yet.");
	choice = run_dialog(1);

	if (choice == 1)
		move_to_new_town(0,11,21);
	if (choice == 2)
		block_entry(1);
 break;

beginstate 11;
	if (get_flag(1,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"A pile of filthy hay has been dumped to the corner of the cell. The reek of urine emitting from it makes you think that whoever was in this cell before you did not use the hay for sleeping on.",0);
		add_dialog_choice(0,"Leave the pile alone.");
		add_dialog_choice(1,"Take a bushel of hay.");
		choice = run_dialog(1);

		if (choice == 2) {
			change_spec_item(2,1);
			set_flag(1,1,1);
}
}
 break; 

beginstate 12;
		set_flag(2,1,21);
	if (party_size() == 1) {
		reset_dialog();
		add_dialog_str(0,"You begin to groan like your insides were on fire. The jailer shouts at you. _Hey! What's gotten into you? Shut up!_ His words are slurred from the wine and they tend to run together.",0);
		add_dialog_str(1,"You continue your show. The bandit gets to his feet and shambles towards your cell. _Shut up, I said!_ He peers at you uncertainly. _What's the matter?_",0);
		add_dialog_choice(0,"There was a spider. It bit me. (*Groan*)");
		run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"The bandit wrinkles his forehead. _What? I didn't see no spider in there._ He eyes your cell with suspicion. You groan theatrically. The bandit fumbles with his keyring. _Now you hold still!_",0);
		add_dialog_str(1,"The door opens and the bandit steps inside the cell. _Where'd the spider go?_ Before the jailer can do anything else you grab him by his leg and knock him over. His head makes an unhealthy sound as it hits the floor.",0);
		add_dialog_str(2,"You take the keyring from the guard.",0);
		run_dialog(1);
		change_spec_item(1,1);
		relocate_character(6,4,13);
		set_character_pose(6,14);
		force_instant_terrain_redraw();
		set_mobility(6,0);
		
}
	if (party_size() > 1) {
		clear_buffer();
		append_char_name(1);
		append_string(" begins to groan like a man whose insides are on fire. The jailer shouts at you. _Hey! What's gotten into you? Shut up!_ His words are slurred from the wine and they tend to run together.");
		get_buffer_text(dlgstr);
		reset_dialog();
		add_dialog_str(0,dlgstr,0);
		add_dialog_str(1,"You continue your show. The bandit gets to his feet and shambles towards your cell. _Shut up, I said!_ He peers at you uncertainly. _What's the matter?_",0);
		clear_buffer();
		append_char_name(1);
		append_string(" got wounded in the battle.");
		get_buffer_text(dlgstr);
		add_dialog_choice(0,dlgstr);
		run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"The bandit wrinkles his forehead. _What? Well like I give a fig! Quite down or I'll come kick you down!_ The groaning continues and the bandit loses his temper. _That does it, y' hear!_",0);
		clear_buffer();
		append_string("The door opens and the bandit steps inside the cell. But before he has the chance to do anything ");
		append_char_name(0);
		append_string(" jumps on him and knocks him down. His head makes an unhealthy sound as it hits the floor.");
		get_buffer_text(dlgstr);	
		add_dialog_str(1,dlgstr,0);
		add_dialog_str(2,"You take the keyring from the guard.",0);
		run_dialog(1);
		change_spec_item(1,1);
		relocate_character(6,4,13);
		set_character_pose(6,14);
		force_instant_terrain_redraw();
		set_mobility(6,0);
		
}

 break;

 beginstate 13;
	if (get_flag(2,0) == 5) {
		set_flag(2,0,6);
		clear_buffer();
		append_string("It's ");
		append_char_name(0);
		append_string("'s.");
		get_buffer_text(dlgstr);
		message_dialog("The iron-barred door creaked so loudly that the jailer stirred from his sleep. He fixes his weary eyes on you and mumbles. _Son of a..._ He gets up with remarkable speed and pulls out a familiar looking weapon.",dlgstr);
		set_attitude(6,10);
}
 break;

 beginstate 14;
	if (get_flag(2,2) == 0) {
		message_dialog("Halter is dead. He lies on his side in his cell. His eyes stare at you unblinking. His mouth hangs open. This is just one more death in the long list the bandits have made since they started plaguing Tonstville.","");
 		set_flag(2,2,1);
}
 break;

 beginstate 15;
	if (get_flag(2,3) == 0) {
		message_dialog("You open the door into a torture chamber. Two dark cages loom to your left. To your right a table holds several bloody tools. The table to the north has a man on it. Two men turn their attention from the poor man on the table to you.","One of them swears and they attack.");
		set_flag(2,3,1);
}
 break;

 beginstate 16;
	if ((get_flag(2,4) == 0) && (get_flag(2,0) != 6)) {
		play_sound(63);
		clear_buffer();
		append_string("He draws a weapon and charges at you. The weapon is ");
		append_char_name(0);
		append_string("'s.");
		get_buffer_text(dlgstr);
		message_dialog("The scream came from the room to the north. You listen carefully and hear someone talking behind the door. You also hear someone getting up behind you. The jailer groans and rubs his head with his hand. He frowns when he sees the blood on his hand.",dlgstr);
		set_flag(2,4,1);
		set_flag(2,0,6);
		set_mobility(6,1);
		set_attitude(6,10);
		set_character_pose(6,0);
}
	if ((get_flag(2,4) == 0) && (get_flag(2,0) == 6)) {
		play_sound(63);
		message_dialog("The scream came from the room to the north. You listen carefully and hear someone talking behind the door. You can't make out the words, but you doubt anything pleasant is going on behind the door.","");
		set_flag(2,4,1);
}
 break;